package com.ysqcould.web.controller.message;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ysqcould.common.annotation.Log;
import com.ysqcould.common.core.controller.BaseController;
import com.ysqcould.common.core.domain.AjaxResult;
import com.ysqcould.common.core.page.TableDataInfo;
import com.ysqcould.common.enums.BusinessType;
import com.ysqcould.common.utils.poi.ExcelUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ysqcould.message.domain.Sms;
import com.ysqcould.message.service.ISmsService;

/**
 * 短信模板Controller
 * 
 * @author jcd
 * @date 2022-09-21
 */
@RestController
@RequestMapping("/message/sms")
public class SmsController extends BaseController
{
    @Autowired
    private ISmsService smsService;

    /**
     * 查询短信模板列表
     */
    @PreAuthorize("@ss.hasPermi('message:sms:list')")
    @GetMapping("/list")
    public TableDataInfo list(Sms sms)
    {
        startPage();
        List<Sms> list = smsService.selectSmsList(sms);
        return getDataTable(list);
    }

    /**
     * 导出短信模板列表
     */
    @PreAuthorize("@ss.hasPermi('message:sms:export')")
    @Log(title = "短信模板", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Sms sms)
    {
        List<Sms> list = smsService.selectSmsList(sms);
        ExcelUtil<Sms> util = new ExcelUtil<Sms>(Sms.class);
        util.exportExcel(response, list, "短信模板数据");
    }

    /**
     * 获取短信模板详细信息
     */
    @PreAuthorize("@ss.hasPermi('message:sms:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(smsService.selectSmsById(id));
    }

    /**
     * 新增短信模板
     */
    @PreAuthorize("@ss.hasPermi('message:sms:add')")
    @Log(title = "短信模板", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Sms sms)
    {
        return toAjax(smsService.insertSms(sms));
    }

    /**
     * 修改短信模板
     */
    @PreAuthorize("@ss.hasPermi('message:sms:edit')")
    @Log(title = "短信模板", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Sms sms)
    {
        return toAjax(smsService.updateSms(sms));
    }

    /**
     * 删除短信模板
     */
    @PreAuthorize("@ss.hasPermi('message:sms:remove')")
    @Log(title = "短信模板", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(smsService.deleteSmsByIds(ids));
    }
}
